﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Domain.Repositories;

namespace CodeMan.Domain.ClassGens
{
    public class ClassGenDataSeederContributor
    : IDataSeedContributor, ITransientDependency
    {
        private readonly IRepository<ClassGen, Int64> _ClassGenRepository;

        public ClassGenDataSeederContributor(IRepository<ClassGen, Int64> ClassGenRepository)
        {
            _ClassGenRepository = ClassGenRepository;
        }

        public async Task SeedAsync(DataSeedContext context)
        {
            if (await _ClassGenRepository.GetCountAsync() <= 0)
            {
                await _ClassGenRepository.InsertAsync(
                    new ClassGen
                    {
                        Name = "1984" 
                    },
                    autoSave: true
                );

                await _ClassGenRepository.InsertAsync(
                    new ClassGen
                    {
                        Name = "The Hitchhiker's Guide to the Galaxy"
                    },
                    autoSave: true
                );
            }
        }
    }
}
